{% extends "base.html" %}
{% block title %}hive数据字典{% endblock %}
{% block contentheader %}Hive数据字典{% endblock %}
{% block contentsmallheader %}所有离线表字段详情{% endblock %}
{% block content %}
    <div class="box box-primary ng-scope">
        <div class="box-header with-border">
            <div class="row">
                <div class="col-md-3">
                    <div class="dropdown">
                        <button class="btn btn-default dropdown-toggle" style="width: 300px" type="button"
                                id="dropdownMenu1"
                                data-toggle="dropdown"
                                style="width: 200px">
                            <i class="fa fa-database"></i>
                            &nbsp 数据库 &nbsp
                            <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1" id="databases"
                            style="height:auto!important;max-height:400px;overflow:auto;width: 300px">
                        </ul>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="dropdown">
                        <button class="btn btn-default dropdown-toggle" type="button" style="width: 300px"
                                id="dropdownMenu2"
                                data-toggle="dropdown"
                                style="width: 200px">
                            <i class="fa fa-table"></i>
                            &nbsp 数据表 &nbsp
                            <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu2" id="tables"
                            style="height:auto!important;max-height:400px;overflow:auto;width: 300px">
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <br/>
        <div class="box-body">
            <div class="panel panel-default" id="panel_db">
                <!-- Default panel contents -->
                <div class="panel-heading" id="div_db">DataBase:</div>
                <div class="panel-body" id="panel_tb">
                    <p>Table:</p>
                    <table class="table table-bordered table-hover table-striped" id="tbl_columns">

                    </table>
                </div>

                <!-- Table -->
                <!--<div>-->
                <!--<table class="table table-bordered table-hover table-striped" id="tbl_columns">-->

                <!--</table>-->
                <!--</div>-->
            </div>
        </div>
    </div>
{% endblock %}

{% block script %}
    <script type="text/javascript" src="static/js/common.js"></script>
    <script type=text/javascript>
        function add_class() {
            $('#treeview2').addClass('active');
            $('#menu2').addClass('menu-open');
            $('#datadict').addClass('active');
        }

        $('ul#tables').on('click', 'li', function () {
            var current_comment = hive_tbl[$(this).children('a').attr("parent")][$(this).children('a').attr("tabindex")][12];
            var current_owner = hive_tbl[$(this).children('a').attr("parent")][$(this).children('a').attr("tabindex")][4];
            var current_type = hive_tbl[$(this).children('a').attr("parent")][$(this).children('a').attr("tabindex")][8];
            var current_time = hive_tbl[$(this).children('a').attr("parent")][$(this).children('a').attr("tabindex")][1];

            if (current_comment != null)
                $('#panel_tb').children('p').html("表名称：<b>" + $(this).children('a').text() + " </b>（创建者：" + current_owner + "，建表时间：" + getLocalTime(current_time) + "，类型：" + current_type + "，注释：" + current_comment + "）");
            else
                $('#panel_tb').children('p').html("表名称：<b>" + $(this).children('a').text() + " </b>（创建者：" + current_owner + "，建表时间：" + getLocalTime(current_time) + "，类型：" + current_type + "）");

            $('#tbl_columns').empty();


            var current_sdid = hive_tbl[$(this).children('a').attr("parent")][$(this).children('a').attr("tabindex")][6];

            $.ajax({
                data: {"sdid": current_sdid, 'tblid': $(this).children('a').attr("tabindex")},
                url: "/get_dict_col",
                context: document.body,
                success: function (data) {
                    var count = 1;
                    $('#tbl_columns').append("<tr><th>ID</th><th>字段名</th><th>字段类型</th><th>分区字段</th><th>注释</th></tr>");
                    for (var i = 0; i < data.data.length; i++) {
                        $('#tbl_columns').append("<tr><td>" + count + "</td><td>" + data.data[i][2] + "</td><td>" + data.data[i][3] + "</td><td>" + data.data[i][5] + "</td><td>" + data.data[i][1] + "</td></tr>");
                        count = count + 1;
                    }
                }
            });
            $('#panel_tb').show();
            $('#tbl_columns').show();
        });


    </script>

{% endblock %}


